﻿using System;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XsltDbClient
{
    public class ServiceUtils
    {
        public static RichXmlClient CreateClient(string domain, string username, string password)
        {
            RichXmlClient client = new RichXmlClient(
                "http://" + domain + "/DesktopModules/XsltDb/Rich.aspx",
                username, password);

            switch (client.Ping())
            {
                case RichXmlClient.PingResult.VER:
                    MessageBox.Show(
                        "Can't connect to the server. Please, use the same version for XsltDb module and Rich Client",
                        "XsltD Rich Client",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);

                    return null;
                case RichXmlClient.PingResult.ERR:
                    MessageBox.Show(
                        "Can't connect to the server",
                        "XsltD Rich Client",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);

                    return null;
                case RichXmlClient.PingResult.PWD:
                    MessageBox.Show(
                        "Login / password dooesn't match or there is no user '" + username + "'",
                        "XsltD Rich Client",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    return null;
            }
            return client;
        }
    }
}
